package com.lanswon.qzsmk.controller.inventoryManageController;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.qzsmk.annotation.SystemControllerLog;
import com.lanswon.qzsmk.base.DwzPage;
import com.lanswon.qzsmk.model.CardTask;
import com.lanswon.qzsmk.service.systemManageService.InventoryManagementService;

import ch.qos.logback.classic.Logger;

@Controller
@RequestMapping(value = "/inventoryMagOfBlankRequiredByEmp")
public class InventoryMagOfBlankRequiredByEmpController {
	
	private final static Logger logger = (Logger) LoggerFactory.getLogger(InventoryMagOfBlankRequiredByEmpController.class);
	
	@Autowired
	InventoryManagementService ims;
	
	@RequiresPermissions("inventoryMagOfBlankRequiredByEmp:index")
	@RequestMapping(name = "柜员领用空白卡出库,inventoryMagOfBlankRequiredByEmp:index",value = "/receiveCardByEmp", method = { RequestMethod.POST, RequestMethod.GET })
	public String receiveCardByEmp(HttpServletRequest request) {
		logger.info("receiveCardByEmp########start");
		logger.info("receiveCardByEmp########end");
		return "EmpReceiveBlankCardRegister";
	}
	
	/**
	 * 请求卡产品类型，和对应的网点的卡产品库存数量
	 * @param request
	 * @return
	 */
	@RequiresPermissions("inventoryMagOfBlankRequiredByEmp:getCardInfoByEmpReceivedCard")
	@RequestMapping(name = "加载空白卡库存数量,inventoryMagOfBlankRequiredByEmp:getCardInfoByEmpReceivedCard",value = "/getCardInfoByEmpReceivedCard", method = {RequestMethod.POST})
	@ResponseBody
	@SystemControllerLog(description = "柜员领用白卡加载卡类型库存数量")
	public Map<String, Object> getCardInfoByEmpReceivedCard(HttpServletRequest request) {
		String cardClassifyDef = request.getParameter("classFyVal");
		String empNo = request.getParameter("empNo");
		String empBranch = request.getParameter("empBranch");
		logger.debug("卡类型分类==>"+cardClassifyDef);
		logger.debug("员工号==>"+empNo);
		logger.debug("员工网点==>"+empBranch);
		Map<String,Object> resultMap =  ims.queryCardAmountInfo(cardClassifyDef,empNo,empBranch);
		return resultMap;
	}
	
	/**
	 * 子模块：柜员领用
	 * 提交信息
	 * @param request
	 * @return
	 */
	@RequiresPermissions("inventoryMagOfBlankRequiredByEmp:queryCardByBlankAppAndBatchApp")
	@RequestMapping(name = "查询空白卡批量卡信息,inventoryMagOfBlankRequiredByEmp:queryCardByBlankAppAndBatchApp",value = "/queryCardByBlankAppAndBatchApp", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> queryCardByBlankAppAndBatchApp(HttpServletRequest request, Integer currentPage, Integer numPerPage) {
		logger.info("queryCardByBlankAppAndBatchApp########start()");
		if (currentPage == null && numPerPage == null) {
			currentPage = 1;
			numPerPage = 10;
		}
		// 接收前画面穿过来数据
		String receiveCardClassify = request.getParameter("receiveCardClassify");
		String requestAmount = request.getParameter("requestAmountByEmpReceive");
		String taskNo = request.getParameter("taskNoByEmpReceive");
		String applyCompany = request.getParameter("applyCompanyByEmpReceive");
		String branchNo = request.getParameter("branchNoByEmpReceive");
		// 装有画面信息的map
		Map<String, String> map = new HashMap<String, String>();
		map.put("receiveCardClassify", receiveCardClassify);
		map.put("requestAmount", requestAmount);
		map.put("taskNo", taskNo);
		map.put("applyCompany", applyCompany);
		map.put("branchNo", branchNo);
		
		DwzPage<CardTask> dpList = ims.getCardInfoByEmpReceive(map, currentPage, numPerPage);
		Map<String, Object> rMap = new HashMap<>();
		rMap.put("list", dpList);
		logger.info("queryCardByBlankAppAndBatchApp#########end()");
		return rMap;
	}
	
	/**
	 * 柜员领用信息提交
	 * @param request
	 * @return
	 * @throws Exception
	 */
	@RequiresPermissions("inventoryMagOfBlankRequiredByEmp:saveBlankCardApplyByEmp")
	@RequestMapping(name = "柜员领用信息提交,inventoryMagOfBlankRequiredByEmp:saveBlankCardApplyByEmp",value="/saveBlankCardApplyByEmp",method=RequestMethod.POST)
	@ResponseBody
	@SystemControllerLog(description = "提交柜员领用")
	public Map<String, Object> saveBlankCardApplyByEmp(HttpServletRequest request) throws Exception{
		
		Map<String, Object> map = new HashMap<>();
		// 打印参数的组装map
		Map<String, Object> rMap = null;

		rMap = ims.ReceiveCardByEmpRegister(request);
		Map<String,Object> pramMap = new HashMap<String,Object>();
		pramMap.put("applyType", rMap.get("credential_type"));
		map.put("ipAddress", rMap.get("ipAddress"));
		map.put("storageNo", rMap.get("storageNo"));
		map.put("max", "true");
		map.put("title", rMap.get("title"));
		map.put("rel", "receiveTask");
		map.put("statusCode", "200");
		map.put("message", "领用成功");
		map.put("param", pramMap);
		map.put("url", "printCredentials/toStoragePdfView");
		
		map.put("jumpToTabid", "receiveCardByEmp");
		map.put("jumpToUrl", "inventoryMagOfBlankRequiredByEmp/receiveCardByEmp");
		map.put("jumpToTile", "柜员领用预制空白卡片");

		return map;
	}
}
